home *** CD-ROM | disk | FTP | other *** search
/ Aminet 15 / Aminet 15 - Nov 1996.iso / Aminet / comm / mail / YamNet.lha / rexxtra12.lha / rexx / Hist.rexx < prev    next >
OS/2 REXX Batch file  |  1990-03-18  |  3KB  |  95 lines

  1. /* Hist.rexx */
  2.  
  3. /*
  4.      Format
  5.  
  6.        HIST [SAVE <name>] [LOAD <name>] [NOCLEAR]
  7.         [ORDER] [PERM [SEARCH <pattern>]
  8.  
  9.    Save and/or recall the history buffer. ORDER places the history
  10.    buffer in alphabetical order and removes duplicates. PERM
  11.    recalls the permanent history file. SEARCH searches the
  12.    history buffer for a pattern.
  13.  
  14. */
  15.  
  16. signal on break_c
  17. call addlib 'rexxextra.library',-20,-30,0
  18.  
  19. facility = 'Hist'
  20. retcode = 0
  21. histfile = 'dat:.History'
  22. permfile = 'Perm'
  23. cmd = ''
  24.  
  25. template = "SAVE/K,LOAD/K,SEARCH/K,NOCLEAR/S,ORDER/S,PERM/S"
  26. dtemplate = "SAVE/K,LOAD/K,NOCLEAR/S,ORDER/S,PERM/S,SEARCH/K"
  27. args. = ''
  28.  
  29. parse arg g_c
  30. do while g_c='?'
  31.   options prompt dtemplate': '  /* this template is      */
  32.   parse pull g_c        /* displayed to the user */
  33.   if g_c='?' then do
  34.     g_s=sourceline(3)
  35.     if pos('/*',g_s)=0 then break; if pos('*/',g_s)>0 then break
  36.     say
  37.     g_s=sourceline(4)
  38.     do i=5 while pos('*/',g_s)=0; say g_s; g_s=sourceline(i); end
  39.     say
  40.     end
  41.   end
  42. interpret Cparse(g_c,template,'args')
  43. if args.ERRCODE > 1 then do; say facility'-E-BADARGS,' args.ERRTEXT; exit 5; end
  44.  
  45. swflags = ''
  46. if args.NOCLEAR then swflags = 'NOCLEAR'
  47. if (args.SAVE ~= '') & (args.LOAD ~= '') then do
  48.   shistfile = fparse(pragma('D'),args.SAVE,histfile)
  49.   lhistfile = fparse(pragma('D'),args.LOAD,histfile)
  50.   if ~exists(lhistfile) then say lhistfile 'does not exist.'
  51.   else do
  52.     if exists(shistfile) then call Dump shistfile
  53.     'SwapHistory SAVE' shistfile 'LOAD' lhistfile swflags
  54.     end
  55.   end
  56. if args.SAVE ~= '' then do
  57.   histfile = fparse(pragma('D'),args.SAVE,histfile)
  58.   if exists(histfile) then call Dump histfile
  59.   'History >'histfile
  60.   end
  61. if args.LOAD ~= '' then do
  62.   histfile = fparse(pragma('D'),args.LOAD,histfile)
  63.   if ~exists(histfile) then say histfile 'does not exist.'
  64.   else 'SwapHistory LOAD' histfile swflags
  65.   end
  66. if args.ORDER then do
  67.   histfile = fparse(pragma('D'),'Hist-Temp',histfile)
  68.   if exists(histfile) then call Dump histfile
  69.   'History | Sort | NoDuplicates >'histfile
  70.   'SwapHistory LOAD' histfile swflags
  71.   end
  72. if args.PERM then do
  73.   call Hist 'LOAD 'permfile swflags
  74.   end
  75. if args.SEARCH ~= '' then do
  76.   'History | Search STDIN nonum quick' args.SEARCH
  77.   end
  78.  
  79. GetOut:
  80. exit retcode
  81.  
  82. break_c:
  83. break_d:
  84. break_e:
  85. break_f:
  86.   say facility'-E-BREAK, Control-C interrupt'
  87.   exit 20
  88. failure:
  89.   say facility'-E-FAIL, Line:' sigl', Error:' rc; retcode = rc; signal GetOut
  90. syntax:
  91.   say facility'-E-SYNTAX, Line:' sigl', Error:' rc; retcode = rc; signal GetOut
  92. error:
  93.   say facility'-E-ERROR, Line:' sigl', Error:' rc; retcode = rc; signal GetOut
  94.  
  95.